package switchviz.recording;

import switchviz.gui.component.JLabeldComponent;
import switchviz.gui.component.PaddingPanel;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;


public class ReplayPanel extends PaddingPanel
{
    //~ Static fields/initializers -----------------------------------------------------------------

    /**
     *
     */
    private static final long serialVersionUID = 2297648500013595614L;

    //~ Instance fields ----------------------------------------------------------------------------

    private JLabeldComponent _lblrecname = null;
    private JLabeldComponent _lblrecswitch = null;
    private JLabeldComponent _lblrecaddress = null;
    private JLabeldComponent _lblrecswitchport = null;
    private JLabeldComponent _lblrecdate = null;
    private JLabeldComponent _lblrectime = null;
    private JLabeldComponent _lblrecords = null;

    //~ Constructors -------------------------------------------------------------------------------

    public ReplayPanel()
    {
        initialize();
    }

    //~ Methods ------------------------------------------------------------------------------------

    public void setRecordModel(RecordDataModel recorddm)
    {
        _lblrecname.setText(recorddm.toString());
        _lblrecdate.setText(recorddm.getDate());
        _lblrectime.setText(String.valueOf((recorddm.getRecEnd() - recorddm.getRecStart()) / 1000) +
            " sec");
        _lblrecswitch.setText(recorddm.getSwitchName());
        _lblrecswitchport.setText(String.valueOf(recorddm.getSwitchPortCount().size()));
        _lblrecaddress.setText(recorddm.getSwitchAddress());

        if ((recorddm.getFolder() != null) && recorddm.getFolder().isDirectory())
        {
            _lblrecords.setText(String.valueOf(recorddm.getFolder().list().length - 1));
        }
    }

    private void initialize()
    {
        //Dimension labelwidth = new Dimension(250, 20);
        this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        this.setBorder(BorderFactory.createTitledBorder("Replay Options"));
        this.setPreferredSize(new Dimension(800, 170));

        _lblrecname = new JLabeldComponent("Name of Record: ", JLabeldComponent.LABEL);
        _lblrecdate = new JLabeldComponent("Date of Record: ", JLabeldComponent.LABEL);
        _lblrectime = new JLabeldComponent("Length of Record: ", JLabeldComponent.LABEL);
        _lblrecswitch = new JLabeldComponent("Switch: ", JLabeldComponent.LABEL);
        _lblrecaddress = new JLabeldComponent("Address: ", JLabeldComponent.LABEL);
        _lblrecords = new JLabeldComponent("Signals recorded: ", JLabeldComponent.LABEL);
        _lblrecswitchport = new JLabeldComponent("Ports at Switch: ", JLabeldComponent.LABEL);

        this.add(_lblrecname);
        this.add(_lblrecdate);
        this.add(_lblrectime);
        this.add(_lblrecswitch);
        this.add(_lblrecaddress);
        this.add(_lblrecswitchport);
        this.add(_lblrecords);
    }
}
